﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Teris
{
    internal class GameScene : ISceneUpdate
    {
        Map map;
        BlockWorker worker;

        

        public GameScene() 
        {    
        }

        public void Start()
        {
            map = new Map();
            worker = new BlockWorker();
            InputBlock.Instance.inputEvent += PlayerInput;
        }

        public void End()
        {
            InputBlock.Instance.inputEvent -= PlayerInput;
        }


        public void Update()
        {
            lock (worker)
            {
                map.Draw();
                worker.AutoDown(map);
                worker.Draw();              
            }

            Thread.Sleep(300);              
        }

        void PlayerInput()
        {

                if (Console.KeyAvailable)
                {
                    lock (worker)
                    {
                        switch (Console.ReadKey(true).Key)
                        {
                            case ConsoleKey.Q:
                                worker.ChangeShap(E_Change_Type.Left, map);
                                break;
                            case ConsoleKey.E:
                                worker.ChangeShap(E_Change_Type.Right, map);
                                break;
                            case ConsoleKey.A:
                                worker.MoveRL(E_Change_Type.Left, map);
                                break;
                            case ConsoleKey.D:
                                worker.MoveRL(E_Change_Type.Right, map);
                                break;
                            case ConsoleKey.S:
                                worker.AutoDown(map);
                                break;
                        }
                    }
                }
             
        }


    }
}
